home *** CD-ROM | disk | FTP | other *** search
- /* eof.c --- p 495 */
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- main()
- {
- int fhandle, total=0, count;
- unsigned char buffer[80];
- /* Open the file "autoexec.bat." Note the two '\' */
- if ( (fhandle = open("c:\\autoexec.bat", O_RDONLY)) == -1)
- {
- printf("open failed");
- exit(1);
- }
- printf("contents of c:autoexec.bat:\n");
- while ( !eof(fhandle)) /* Read until EOF */
- {
- if ((count = read(fhandle, buffer, 80)) == -1)
- {
- perror("read error");
- break; /* exit from while loop */
- }
- total += count;
- write(1, buffer, count);
- }
- printf("=== %d bytes read ===\n", total);
- }